using CriWare;
using UnityEngine;

namespace IQIGame.Onigao.Game.Assets.Scripts.Main.Runtime.Media
{
    public class VideoPlayerForRender : VideoPlayerBase
    {
        protected override CriManaMovieMaterial CreateRawPlayer(Transform root, bool applyTargetAlpha, bool additiveMode)
        {
            var go = new GameObject(nameof(_rawVideoPlayer));
            go.transform.SetParent(root);
            go.SetActive(false);
            _rawVideoPlayer = go.AddComponent<CriManaMovieController>();
            _rawVideoPlayer.applyTargetAlpha = applyTargetAlpha;
            _rawVideoPlayer.additiveMode = additiveMode;
            go.SetActive(true);
            return _rawVideoPlayer;
        }


        /// <summary>
        /// 后续重载
        /// </summary>
        /// <param name="rimg"></param>
        public void SetVideoTarget(UnityEngine.Renderer render)
        {
            (_rawVideoPlayer as CriManaMovieController).target = render;
            if (render != null)
            {
                _rawVideoPlayer.enabled = true;
            }
        }

        protected override bool CheckVideoTarget()
        {
            var renderVideoPlayer = (_rawVideoPlayer as CriManaMovieController);
            if (renderVideoPlayer != null)
            {
                return renderVideoPlayer.target != null;
            }
            return false;
        }

        public override void OnReset()
        {
            var renderVideoPlayer = (_rawVideoPlayer as CriManaMovieController);
            if (renderVideoPlayer != null)
            {
                renderVideoPlayer.target = null;
            }

            base.OnReset();
        }


    }
}
